package org.example.juc;

import java.util.HashSet;
import java.util.Set;

public class VolTest2 {
    private static int x = 0, y = 0;
    private static int a = 0, b = 0;

    public static void main(String[] args) throws Exception{
        Set<String> set = new HashSet<>();
        int i = 0;
        for (;;) {
            i++;
            x = 0;
            y = 0;
            a = 0;
            b = 0;
            Thread one = new Thread(()->{
                a = y;
                x = 1;
            });
            Thread two = new Thread(() -> {
                b = x;
                y = 1;
            });
            one.start();
            two.start();
            one.join();
            two.join();
            if (a == 1 && b == 1) {
                System.out.println("指令重排" + i);
                break;
            }
        }
    }
}
